package com.rpframework.website.device.act.admin;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.rpframework.core.api.FileService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.domain.Order;
import com.rpframework.website.device.service.OrderService;

/**
 * 
 * @author zl
 * @date 2016年1月18日 上午9:42:02
 * 
 */
@Controller
@RequestMapping("/admin/order")
public class AdminOrderAct extends AdminAct{
	@Resource OrderService service;
	@Resource FileService fileService;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping("/list")
	public String list(@RequestParam(value="pager", required=false) Pager pager, 
			@RequestParam(value="state", required=false) Integer state, 
			@RequestParam(value="status", required=false) Integer status, 
			Map<Object, Object> model){
		if(pager == null) {
			pager = new Pager();
		}
		if(NumberUtils.isValid(state)){
			pager.getSearchMap().put("state", state.toString());
			model.put("state", state);
		}
		if(NumberUtils.isValid(status)){
			pager.getSearchMap().put("status", status.toString());
			model.put("status", status);
		}
		pager = service.getPager(pager);
		model.put("pager", pager);
		return this.doPackageURI("order/list");
	}
	
	@RequestMapping("/sendGoods")
	public String sendGoods(@RequestParam(value="id", required=false) String id,RedirectAttributes attr){
		Order t = service.select(id);
		t.setStatus(3);//后台确认配送
		t.setModifyTime(System.currentTimeMillis()/1000);
		boolean flag =service.update(t);
		if(flag){
				setInfoMsg("确认配送成功！", attr);
		}else{
			setInfoMsg("确认配送失败！", attr);
		}
		return redirect("/admin/order/list");
	}
}
